package com.tanhua.model.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;

/**
 * 分页对象
 * @param <T>
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class PageResult<T> implements Serializable {

    private Long counts = 0l;//总记录数
    private Long pagesize;//页大小
    private Long pages = 0l;//总页数
    private Long page;//当前页码
    private List<T> items = Collections.emptyList(); //列表

    public PageResult(Long page,Long pagesize,Long counts,List<T> list) {
        this.page = page;
        this.pagesize = pagesize;
        this.items = list;
        this.counts = counts;
        this.pages = counts % pagesize == 0 ? counts / pagesize : counts / pagesize + 1;
    }
}